<template>
    <div>
<h1>医生信息添加</h1>
<table class="table">
<tbody>
    <tr>
        <td>医生姓名</td>
        <td>
            <input type="text" v-model="da.yiName">
        </td>
    </tr>

     <tr>
        <td>医生头像</td>
        <td>
            <input type="file" @change="sc">
            <img :src="'https://localhost:7120/'+da.touXiang"  style="height: 60px;width: 60px;">
        </td>
    </tr>

     <tr>
        <td>科室</td>
        <td>
            <select v-model="da.keShiId">
                <option  :value="0">请选择</option>
                <option v-for="a in ba" :value="a.kId">{{ a.ksName }}</option>
            </select>
        </td>
    </tr>

     <tr>
        <td></td>
        <td>
            <input type="button" value="添加" @click="add">
        </td>
    </tr>
</tbody>
</table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
const uc=useRouter()


//m
const da=ref({
     "yiSId": 0,
  "yiName": "",
  "touXiang": "",
  "keShiId": 0,
  "yiCreateTime": "2025-05-19T04:19:41.951Z"
})

onMounted(()=>{
    bang()
})

//绑定的m
const ba=ref([{
    "kId": 1,
    "ksName": "",
    "ksCount": 0,
    "ksMiaoShu": "",
    "ksCreateTime": "2025-05-19T11:29:32.2299346",
    "ksIsDel": false
  }])

  //绑定
  const bang=()=>{
    axios.get("/api/YiS/BangKs").then(res=>{
        ba.value=res.data;
    })
  }

//添加
const add=()=>{
if(da.value.yiName==""){
    alert("医生姓名不能为空")
    return;
}

if(da.value.keShiId==0){
    alert("请选择科室");
    return
}


    axios.post("/api/YiS/AddYiS",da.value).then(res=>{
        if(res.data>0){
            alert("添加成功");
            uc.push({path:"/showys"})
        }else{
            alert("添加失败")
        }
    })
}

//上传
const sc=(x:any)=>{
    var a=x.target.files[0];
    var b=new FormData();

    b.append("file",a);

if(a.size>2*1024*1024){
    alert("文件大小不能超过2MB")
    return 
}

    axios.post("/api/YiS/SC",b).then(res=>{
        da.value.touXiang=res.data
    })
}
</script>

<style scoped>

</style>